package com.iss.examsys.ejb;

import com.iss.examsys.entity.SubjectTag;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author MA
 */
@Stateless
public class SubjectTagBean {
    @PersistenceContext EntityManager em;

    public void create(SubjectTag entity){
        em.persist(entity);
    }
    
    public void edit(SubjectTag entity) {
        em.merge(entity);
    }
    
    public void remove(SubjectTag entity) {
        em.remove(em.merge(entity));
    }
    
    public SubjectTag findById(Long id){        
        SubjectTag entity = em.find(SubjectTag.class, id);        
        return entity;
    }
    
    public List<SubjectTag> findAll(){
        TypedQuery<SubjectTag> result = em.createNamedQuery("SubjectTag.findAll", SubjectTag.class);        
        return result.getResultList();
    } 
    
    public List<SubjectTag> findByName(String name){
        TypedQuery<SubjectTag> result = em.createNamedQuery("SubjectTag.findByName", SubjectTag.class);
        result.setParameter("name", name);
        return result.getResultList();
    }
}
